import request from '@/config/axios'
import { yuanToFen } from '@/utils'

// 功能 VO
export interface FunctionVO {
  id: number // ID
  name: string // 功能名称
  price: number // 价格
  description: string // 描述
  status: number // 状态
  picUrl: string // 宣传图
  params: string // 参数
  typeId: number // 功能类型
  typeName: string //类型名称
}

// 功能 API
export const FunctionApi = {
  // 查询功能分页
  getFunctionPage: async (params: any) => {
    return await request.get({ url: `/package/function/page`, params })
  },

  // 查询功能详情
  getFunction: async (id: number) => {
    return await request.get({ url: `/package/function/get?id=` + id })
  },

  // 新增功能
  createFunction: async (data: FunctionVO) => {
    data.price = yuanToFen(data.price);
    return await request.post({ url: `/package/function/create`, data })
  },

  // 修改功能
  updateFunction: async (data: FunctionVO) => {
    if(data.price !== undefined && data.price != null){
      data.price = yuanToFen(data.price)
    }
    return await request.post({ url: `/package/function/update`, data })
  },

  // 删除功能
  deleteFunction: async (id: number) => {
    return await request.get({ url: `/package/function/delete?id=` + id })
  },

  // 导出功能 Excel
  exportFunction: async (params) => {
    return await request.download({ url: `/package/function/export-excel`, params })
  },

  getFunctionList: async () => {
    return await request.get({ url: `/package/function/list`})
  }
}